import java.util.Scanner;
import static java.lang.Math.pow;

public class NumberDaffodils {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 10; i < n; i++) {
            int tem = i;
            int sum = 0;
            int count = 0;
            while (tem != 0) {
                count++;
                tem/=10;
            }
            tem = i;
            while (tem != 0) {
                int j = tem%10;
                sum += pow(j,count);
                tem/=10;
            }
            if(sum == i){
                System.out.print(i +" ");
            }
        }
    }
}
